/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package mytools;
import java.sql.*;
import javax.sql.DataSource;
import javax.naming.*;
/**
 *
 * @author xiaoxiao
 */
public class dbcon {
    public static  Connection getConnection() throws Exception
    {
        try
        {
            Context initCtx=new javax.naming.InitialContext();
            DataSource ds=(DataSource)initCtx.lookup("java:comp/env/jdbc/mysql");
            return ds.getConnection();
        }
        catch(SQLException e)
        {
            throw e;
        }
        catch(NamingException e)
        {
            throw e;
        }
    }

}
